/**
 * 需求：统计（2003年-2022年）全国离婚登记数最高的年份
 * 求和sum并
 */

package DivorceTopOne4;


import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class DivorceTopOneMapper extends Mapper<LongWritable, Text,DivorceBean, NullWritable> {

    DivorceBean outKey = new DivorceBean();
    NullWritable outValue = NullWritable.get();

    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, DivorceBean, NullWritable>.Context context) throws IOException, InterruptedException {
        String[] fields = value.toString().split("\t");
        if (fields.length == 2){
            String province = fields[0].split(",")[0].split("=")[1];
            String city = fields[0].split(",")[1].split("=")[1];

            float divorce = Float.parseFloat( fields[1] );

            outKey.set(province,city,divorce);

            context.write(outKey,outValue);
    }
  }
}
